package Outil;

/***********************************************************************
 * Module: Buffer.java Author: 12008505 Purpose: Defines the Class Buffer
 ***********************************************************************/

/**
 * Originator
 */
public class Buffer {

	private StringBuffer Ztravail;

	public Buffer() {
		Ztravail = new StringBuffer();
	}

	public void ajouterZoneDeTravailChar(char c, int debut) {
		System.out.println("le debut :" + debut);
		if (Ztravail.length() < debut) {
			debut = Ztravail.length();
		}
		Ztravail.insert(debut, c);

	}

	public void setZtravail(StringBuffer ztravail) {
		Ztravail = ztravail;
	}

	public void ajouterZoneDeTravailString(String s, int debut) {
		if (Ztravail.length() < debut) {
			debut = Ztravail.length();
		}
		Ztravail.insert(debut, s);
	}

	public StringBuffer getZoneDeTravail() {
		return Ztravail;
	}

	public void supprimer(int debut, int fin) {
		Ztravail.delete(debut, fin);
	}

	public String getSelectedText(int debut, int fin) {
		System.out.println("lenght de ztravail:" + Ztravail.length());
		if (Ztravail.length() < fin) {
			int bias = fin - Ztravail.length();
			fin = Ztravail.length();
			debut = debut - bias;
		}
		return Ztravail.substring(debut, fin);
	}

	public String getText() {
		return Ztravail.substring(0);
	}

}